﻿using System;

namespace DynamicViewModel.Tests.TestTypes
{
    public sealed class ContactDetails
    {
        private String _firstName;
        private String _lastName;
        private String _fullName;
        private String _reversedFullName;

        public String FirstName
        {
            get
            {
                return _firstName;
            }

            set
            {
                _firstName = value;

                SetFullName();
                SetReversedFullName();
            }
        }

        public String LastName
        {
            get
            {
                return _lastName;
            }

            set
            {
                _lastName = value;

                SetFullName();
                SetReversedFullName();
            }
        }

        public Int32 Age { get; private set; }

        public String FullName
        {
            get
            {
                return _fullName;
            }

            set
            {
                _fullName = value;
            }
        }

        public String ReversedFullName
        {
            get
            {
                return _reversedFullName;
            }

            set
            {
                _reversedFullName = value;
            }
        }

        public void SetAge(Int32 age)
        {
            Age = age;
        }

        public void ClearFullName()
        {
            FirstName = String.Empty;
            LastName = String.Empty;
        }

        private void SetFullName()
        {
            FullName = FirstName + " " + LastName;
        }

        private void SetReversedFullName()
        {
            ReversedFullName = Reverse(FullName);
        }

        private static String Reverse(String s)
        {
            Char[] charArray = s.ToCharArray();
            Array.Reverse(charArray);
            return new String(charArray);
        }
    }
}
